﻿<UserControl x:Class="Hisaab.Client.Modules.Core.Transaction.View.TransactionEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Converters="clr-namespace:Hisaab.Client.Modules.Core.Converters"
             xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
             mc:Ignorable="d" d:DesignHeight="652" d:DesignWidth="726" >
    <UserControl.Resources>
        <Converters:AccountTypeImageConverter x:Key="accountImageConverter" UseLargeIcon="False"/>
        <Converters:TransactionTypeImageConverter x:Key="transactionImageConverter" UseLargeIcon="False"/>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="29" />
            <ColumnDefinition Width="120" />
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="250" />
            <ColumnDefinition Width="32*" />
            <ColumnDefinition Width="285*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="29" />
            <RowDefinition Height="78" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="70" />
            <RowDefinition Height="36" />
            <RowDefinition Height="36" />
            <RowDefinition Height="*" />
            <RowDefinition Height="36" />
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding DialogTypeString}" Style="{DynamicResource MetroHeader}" HorizontalAlignment="Right" />
        <TextBlock Grid.Row="1" Grid.Column="3" Text="Transaction" Style="{DynamicResource MetroHeader2}" HorizontalAlignment="Left" />

        <Label Grid.Column="1" Grid.Row="2" Content="Title" Style="{DynamicResource EditorLabel}" />
        <TextBox Grid.Column="3" Grid.Row="2" Text="{Binding Path=SelectedTransaction.Title, Mode=TwoWay, ValidatesOnDataErrors=True}" Style="{DynamicResource EditorTextBox}" />

        <Label Grid.Column="1" Grid.Row="3" Content="Amount" Style="{DynamicResource EditorLabel}" />
        <TextBox Grid.Column="3" Grid.Row="3" Text="{Binding Path=SelectedTransaction.Amount, StringFormat='{}{0:C}', Mode=TwoWay, ValidatesOnDataErrors=True}" Style="{DynamicResource EditorTextBox}" />

        <Label Grid.Column="1" Grid.Row="4" Content="Account" Style="{DynamicResource EditorLabel}" />
        <ComboBox Grid.Column="3" Grid.Row="4"
            ItemsSource="{Binding Path=Accounts}"
            SelectedValuePath="AccountId"
            SelectedValue="{Binding Path=SelectedTransaction.Account, Mode=TwoWay}" Style="{DynamicResource EditorComboBox}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" >
                        <Image Source="{Binding AccountType, Converter={StaticResource accountImageConverter}}" Margin="3 3 10 3"/>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <Label Grid.Column="1" Grid.Row="5" Content="Type" Style="{DynamicResource EditorLabel}" />
        <ComboBox Grid.Column="3" Grid.Row="5"
            ItemsSource="{Binding Path=TransactionTypes}"
            SelectedValuePath="Key"
            SelectedValue="{Binding Path=SelectedTransaction.TransactionType, Mode=TwoWay}" Style="{DynamicResource EditorComboBox}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" >
                        <Image Source="{Binding Key, Converter={StaticResource transactionImageConverter}}" Margin="3 3 10 3"/>
                        <TextBlock Text="{Binding Value}" VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <Label Grid.Column="1" Grid.Row="6" Content="Date" Style="{DynamicResource EditorLabel}" />
        <DatePicker Grid.Column="3" Grid.Row="6" SelectedDate="{Binding Path=SelectedTransaction.Date, Mode=TwoWay, ValidatesOnDataErrors=True}" Style="{DynamicResource EditorDatePicker}" />

        <Label Grid.Column="1" Grid.Row="7" Content="Tags" Style="{DynamicResource EditorLabel}" Margin="0,0,0,3" Grid.RowSpan="2" />
        <extToolkit:CheckComboBox Grid.Column="3" Grid.Row="7" Style="{DynamicResource EditorMultiComboBox}"
                               SelectedValue="{Binding Path=SelectedTransaction.TagsValue, Mode=OneWay}"
                               SelectedItems="{Binding Path=SelectedTransaction.Tags, Mode=TwoWay}"
                               ItemsSource="{Binding Path=Tags}"
                               DisplayMemberPath="Name"
                               ValueMemberPath="TagId" />
        <Label Grid.Column="5" Grid.Row="2" Content="Details" Style="{DynamicResource EditorLabel}" Margin="0,0,165,0" />
        <TextBox Grid.Column="5" Grid.Row="3" Text="{Binding Path=SelectedTransaction.Details, Mode=TwoWay}" Style="{DynamicResource EditorTextBox}" Margin="0,0,35,0" Grid.RowSpan="5" />

        <Image Grid.Column="3" Grid.Row="8" HorizontalAlignment="Center" Stretch="None" VerticalAlignment="Center"
    	       Visibility="{Binding SelectedTransaction.IsTransferTransaction, Converter={StaticResource VisibilityConverter}, UpdateSourceTrigger=PropertyChanged}"
    	       Source="pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/64/down.png" />

        <Label Grid.Column="1" Grid.Row="9" Content="Account" Style="{DynamicResource EditorLabel}" Visibility="{Binding SelectedTransaction.IsTransferTransaction, Converter={StaticResource VisibilityConverter}, UpdateSourceTrigger=PropertyChanged}" />
        <ComboBox Grid.Column="3" Grid.Row="9"
        ItemsSource="{Binding Path=Accounts}"
        SelectedValuePath="AccountId"
        SelectedValue="{Binding Path=SelectedTransaction.LinkedTransactionAccount, Mode=TwoWay}" Style="{DynamicResource EditorComboBox}"
        Visibility="{Binding SelectedTransaction.IsTransferTransaction, Converter={StaticResource VisibilityConverter}, UpdateSourceTrigger=PropertyChanged}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" >
                        <Image Source="{Binding AccountType, Converter={StaticResource accountImageConverter}}" Margin="3 3 10 3"/>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <Label Grid.Column="1" Grid.Row="10" Content="Date" Style="{DynamicResource EditorLabel}" Visibility="{Binding SelectedTransaction.IsTransferTransaction, Converter={StaticResource VisibilityConverter}, UpdateSourceTrigger=PropertyChanged}" />
        <DatePicker Grid.Column="3" Grid.Row="10"
                    SelectedDate="{Binding Path=SelectedTransaction.LinkedTransactionDate, Mode=TwoWay}"
                    Style="{DynamicResource EditorDatePicker}"
                    Visibility="{Binding SelectedTransaction.IsTransferTransaction, Converter={StaticResource VisibilityConverter}, UpdateSourceTrigger=PropertyChanged}" />
        <StackPanel Grid.Column="0"  Grid.ColumnSpan="6" Grid.Row="12" HorizontalAlignment="Right" Orientation="Horizontal">
            <Button IsDefault="True" Width="75" Command="{Binding SaveCommand}">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/16/save.png" Width="16" Height="16" Margin="0 0 5 0" />
                        <TextBlock>Save</TextBlock>
                    </StackPanel>
                </Button.Content>
            </Button>
            <Button IsCancel="True" Width="75" Command="Close" >Cancel</Button>
        </StackPanel>
    </Grid>
</UserControl>